<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="../../include/tag.jsp" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <title>${mallCategory.name}</title>
    <link rel="stylesheet" href="${ctx}/css/common/list.css">
    <link rel="stylesheet" href="${ctx}/css/common/table.css">
    <%@include file="../../include/commonFile.jsp" %>
</head>
<body>
<!--头部-->
<%@include file="../../include/header.jsp" %>
<div class="index-outside">
    <%@include file="../../include/sidebar.jsp" %>
    <!--内容-->
    <section>
        <div class="section-main">
            <form class="layui-form" action="${ctx}/mall/category/brandList.do" id="myForm" method="post">
                <input type="hidden" name="categoryId" value="${mallCategory.id}"/>
            </form>
            <div class="list-content">
                <div class="cl">
                    <table class="layui-table">
                        <colgroup>
                            <col>
                            <col>
                        </colgroup>
                        <thead>
                        <tr>
                            <th>名称</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:if test="${fn:length(list) == 0}">
                            <tr>
                                <td colspan="2">还没有添加品牌</td>
                            </tr>
                        </c:if>
                        <c:forEach var="brand" items="${list}">
                            <tr data-id="${brand.id}">
                                <td>
                                    <div class="dib ellipsis-1" title="${brand.name}">${brand.name}</div>
                                </td>
                                <td class="tb-opts">
                                    <div class="comm-opts">
                                        <a class="red"
                                           href="javascript:txz.deleteObject('确定要移除该品牌？','${ctx}/mall/brand/deleteCategoryBrand.do?brandId=${brand.id}&categoryId=${mallCategory.id}','已分配给商品，不能移除')">
                                            <i class="iconfont icon-delete btn-icon"></i> 移除
                                        </a>
                                    </div>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </div>
            </div>
        </div><!--底部-->
        <%@include file="../../include/footer.jsp" %>
    </section>
</div>

<script type="text/javascript" src="${ctx}/script/common/list.js"></script>
<script type="text/javascript" src="${ctx}/script/common/table_option.js"></script>
<script type="text/javascript">
    function selectBrand() {
        var useIdArray = new Array();
        $("tbody tr").each(function (index, ele) {
            useIdArray.push($(ele).data("id"));
        });
        var requestUrl = "${ctx}/mall/brand/selectBrandDialog.do?brandIds=" + useIdArray.join(",");
        layer.open({
            type: 2,
            area: ["600px", "400px"],
            title: "添加品牌",
            maxmin: true,
            content: requestUrl,
            btn: ['确定', '关闭'],
            yes: function (index, layero) {
                var body = layer.getChildFrame('body', index);
                var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                var inputForm = body.find('#inputForm');
                var top_iframe = '_parent';
                inputForm.attr("target", top_iframe);//表单提交成功后，从服务器返回的url在当前tab中展示

                var array = iframeWin.contentWindow.doSubmit();
                var idArray = new Array();
                for (var i = 0; i < array.length; i++) {
                    idArray.push(array[i].id);
                }

                $.post("${ctx}/mall/brand/saveCategoryBrand.do", {
                    categoryId: '${mallCategory.id}',
                    brandIds: idArray.join(",")
                }, function (res) {
                    if (res.success) {
                        util.layerMsgSuccess("提交成功", function () {
                            submitFunction('#myForm');
                        })
                    } else {
                        util.layerMsgError("添加失败")
                    }
                })
            }
        })
    }
</script>
<script type="text/javascript">
    txz.initHeader({
        nav: [{
            name: '分类管理',
            href: '${ctx}/mall/brand/list.do'
        }, {
            name: '${mallCategory.name}',
            curr: true
        }, {
            name: '品牌列表'
        }],
        info: '<span class="f12">共<b id="totalCount">${fn:length(list)}</b>条记录</span>',
        btns: [{
            name: '添加品牌',
            icon: 'add',
            href: 'javascript:selectBrand();'
        }, {
            name: '返回',
            icon: 'back',
            href: '${ctx}/mall/category/list.do'
        }]
    });
</script>
</body>
</html>